// Copyright (C) 2010 algebra-1-console-window-calculator.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.0.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License 3.0 for more details.

// A copy of the GPL 3.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official SVN repository and contact information can be found at
// http://code.google.com/p/mcdougal-littell-algebra-1-2004-problem-solver/

#include <iostream>
#include <string>

using namespace std;

string Convert_To_Lower(string Converted_To_Lower)
{
	for(int i=0;i<Converted_To_Lower.length();i++)
		{
			Converted_To_Lower[i]=tolower(Converted_To_Lower[i]);
		}
	return Converted_To_Lower;
}

bool Is_Digit(string Number_To_Check)
{
	bool Is_Digit(true);
	for(int i=0;i<Number_To_Check.length();i++)
			{
				if(isdigit(Number_To_Check[i]))
				{
				}
				else
				{
					Is_Digit=false;
				}
			}
	return Is_Digit;
}

int main()
{
	bool Loop(true);
	while(Loop==true)
	{
		cout<<"Enter the chapter of the problem (Type help for more info): ";
		string Chapter;
		getline(cin,Chapter);
		Chapter=Convert_To_Lower(Chapter);
		if(Chapter=="help")
		{ 
			cout<<"\n";
			cout<<"1.2 = Exponents and powers\n";
			cout<<"3.1 = Solving equations using addition and subtraction\n";
			cout<<"4.4 = The slope of a line\n";
			//cout<<"5.1 = Writing linear equations in slope-intercept form\n";
			//cout<<"9.1 = Solving quadratic equations by finding square roots\n";
			//cout<<"9.6 = Applications of the discriminant\n";
			//cout<<"10.7 = Factoring special products\n";
			cout<<"Credits = Display credits\n";
			cout<<"License = Displays information related to the project's license(GPL 3.0)\n";
			cout<<"Help = Displays the help menu\n";
			cout<<"Support = Support\n";
			cout<<"Exit = Exits The Program\n\n";
		}
		else if(Chapter=="credits")
		{ 
			cout<<"\n";
			cout<<"Main Developer - cmccmc\n";
			cout<<"Project Contributers - zachechooff\n\n";
		}
		else if(Chapter=="license")
		{
			cout<<"\n";
			cout<<"Copyright (C) 2010 algebra-1-console-window-calculator.\n";
			cout<<"This program is free software: you can redistribute it and/or modify\n";
			cout<<"it under the terms of the GNU General Public License as published by\n";
			cout<<"the Free Software Foundation, version 3.0.\n";
			cout<<"\n";
			cout<<"This program is distributed in the hope that it will be useful,\n";
			cout<<"but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
			cout<<"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the:\n";
			cout<<"GNU General Public License 3.0 for more details.\n";
			cout<<"\n";
			cout<<"A copy of the GPL 3.0 should have been included with the program.\n";
			cout<<"If not, see http://www.gnu.org/licenses/ \n";
			cout<<"Official SVN repository and contact information can be found\n";
			cout<<"at http://code.google.com/p/mcdougal-littell-algebra-1-2004-problem-solver/ \n\n";
		}
		else if(Chapter=="exit")
		{
			return 0;
		}
		else if(Chapter=="support")
		{
			cout<<"\nIf you require any assistance please email gcnwiiuploader@gmail.com\n\n";
		}
		else if(Chapter=="1.2")
		{
			cout<<"Enter the base: ";
			string Base;
			getline(cin, Base);
			bool Number=Is_Digit(Base);			
			if(Number==true)
			{
				cout<<"Enter the exponent: ";
				string Exponent;
				getline(cin,Exponent);
				Number=Is_Digit(Exponent);
				if(Number==true)
				{
					double Base_2=atof(Base.c_str());
					double Exponent_2=atof(Exponent.c_str());
					double Result (1);
					for (int Loop=0;Loop<Exponent_2;Loop++)
					{
						Result=Result*Base_2;
					}
					cout<<Result<<"\n";
				}
				else
				{
					cout<<Exponent<<" is not a valid integer\n";
				}

			}
			else
			{
				cout<<Base<<" is not a valid integer\n";
			}
		}
		else if(Chapter=="3.1")
		{
			cout<<"Enter the problem in the format a+b=c\n";
			cout<<"Enter b's value: ";
			string B;
			getline(cin,B);
			bool Number=Is_Digit(B);
			if(Number==true)
			{
				cout<<"Enter c's value: ";
				string C;
				getline(cin,C);
				Number=Is_Digit(C);
				if(Number==true)
				{
					double B_2=atof(B.c_str());
					double C_2=atof(C.c_str());
					cout<<C_2-B_2<<"\n";
				}
				else
				{
					cout<<C<<" is not a valid integer\n";
				}
			}
			else
			{
				cout<<B<<" is not a valid integer\n";
			}
		}
		else if(Chapter=="4.4")
		{
			cout<<"Enter y1: ";
			string y1;
			getline(cin,y1);
			bool Number=Is_Digit(y1);
			if(Number==true)
			{
				cout<<"Enter y2: ";
				string y2;
				getline(cin,y2);
				Number=Is_Digit(y2);
				if(Number==true)
				{
					cout<<"Enter x1: ";
					string x1;
					getline(cin,x1);
					Number=Is_Digit(x1);
					if(Number==true)
					{
						cout<<"Enter x2: ";
						string x2;
						getline(cin,x2);
						Number=Is_Digit(x2);
						if(Number==true)
						{
							double y1_2=atof(y1.c_str());
							double y2_2=atof(y2.c_str());
							double x1_2=atof(x1.c_str());
							double x2_2=atof(x2.c_str());
							cout<<(y2_2-y1_2)/(x2_2-x1_2)<<"\n\n";
						}
						else
						{
							cout<<x2<<" is not a valid integer\n";
						}
					}
					else
					{
						cout<<x1<<" is not a valid integer\n";
					}
				}
				else
				{
					cout<<y2<<" is not a valid integer\n";
				}
			}
			else
			{
				cout<<y1<<" is not a valid integer\n";
			}
		}
		else if(Chapter=="5.1")
		{
			cout<<"Enter the slope: ";
			string Slope;
			getline(cin,Slope);
			bool Number(Is_Digit(Slope));
			if(Number==true)
			{
				cout<<"Enter the y-intercept: ";
				string Y_Intercept;
				getline(cin,Y_Intercept);
				Number=Is_Digit(Y_Intercept);
				if(Number==true)
				{
					double Slope_2=atof(Slope.c_str());
					double Y_Intercept_2=atof(Y_Intercept.c_str());
					cout<<"y="<<Slope_2<<"x";
					if(Y_Intercept_2>0)
					{
						cout<<"+";
					}
					else if(Y_Intercept_2!=0)
					{
					cout<<Y_Intercept_2<<"\n";
					}
					else
					{
						cout<<"\n";
					}
				}
				else
				{
					cout<<Y_Intercept<<" is not a valid integer\n";
				}
			}
			else
			{
				cout<<Slope<<" is not a valid integer\n";
			}
		}
	}
}
